// app.js
import './utils/utils'
import './utils/http'
App({
  globalData: {},
  onLaunch() {
    this.getToken()
    this.getRefreshToken()
  },
  // 从本地获取token，并存到全局
  getToken() {
    // 读取本地存储中的token
    wx.getStorage({
      key: 'token',
      success: (res) => {
        console.log(res.data);
        this.token = res.data
      }
    })
  },
  // 从本地获取refreshtoken，并存到全局
  getRefreshToken() {
    // 读取本地存储中的token
    wx.getStorage({
      key: 'refreshtoken',
      success: (res) => {
        console.log(res.data);
        this.refreshtoken = res.data
      }
    })
  },
  setToken(token, refreshtoken) {
    wx.setStorageSync(
      'token',
      `Bearer ${token}`
    )
    this.token = `Bearer ${token}`
    wx.setStorageSync(
      'refreshtoken',
      `Bearer ${refreshtoken}`
    )
    this.refreshtoken = `Bearer ${refreshtoken}`
  }
})
